<?php


namespace plugin\agent\app\admin\controller;

use app\common\controller\BaseAdminController;
use plugin\agent\app\admin\logic\AgentWithdrawalLogic;
use plugin\agent\app\admin\validate\AgentWithdrawalValidate;
use think\db\Query;

/**
 * 佣金提现
 * Class AgentWithdrawalController
 * @package plugin\agent\app\admin\controller
 */
class AgentWithdrawalController extends BaseAdminController
{
    protected function init()
    {
        parent::init();
        $this->logic = new AgentWithdrawalLogic();
        $this->validate = new AgentWithdrawalValidate();
    }

    public function list()
    {
        $where = [];
        $this->form['user_id'] && $where[] = ['user_id', '=', $this->form['user_id']];
        $this->form['status'] && $where[] = ['status', '=', $this->form['status']];
        $query = $this->logic->search($where);
        $query->order("id desc");
        $query->with([
            'user' => function (Query $query) {
                $query->field([
                    'id',
                    'nickname',
                    'mobile',
                ]);
            },
        ]);
        $data = $this->logic->getPageList($query);
        return $this->success($data);
    }

    public function agree()
    {
        $this->validate->checkData(input(), 'agree');
        $this->logic->agree(input());
        return $this->success();
    }

    public function refuse()
    {
        $this->validate->checkData(input(), 'agree');
        $this->logic->refuse(input());
        return $this->success();
    }

}